home *** CD-ROM | disk | FTP | other *** search
/ Aminet 40 / Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso / Aminet / dev / lang / Python16_Src.lha / Python16_Source / Include / grammar.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-03  |  2.1 KB  |  94 lines

  1. #ifndef Py_GRAMMAR_H
  2. #define Py_GRAMMAR_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6.  
  7. /* Grammar interface */
  8.  
  9. #include "bitset.h" /* Sigh... */
  10.  
  11. /* A label of an arc */
  12.  
  13. typedef struct {
  14.     int    lb_type;
  15.     char    *lb_str;
  16. } label;
  17.  
  18. #define EMPTY 0        /* Label number 0 is by definition the empty label */
  19.  
  20. /* A list of labels */
  21.  
  22. typedef struct {
  23.     int    ll_nlabels;
  24.     label    *ll_label;
  25. } labellist;
  26.  
  27. /* An arc from one state to another */
  28.  
  29. typedef struct {
  30.     short        a_lbl;        /* Label of this arc */
  31.     short        a_arrow;    /* State where this arc goes to */
  32. } arc;
  33.  
  34. /* A state in a DFA */
  35.  
  36. typedef struct {
  37.     int         s_narcs;
  38.     arc        *s_arc;        /* Array of arcs */
  39.     
  40.     /* Optional accelerators */
  41.     int         s_lower;    /* Lowest label index */
  42.     int         s_upper;    /* Highest label index */
  43.     int        *s_accel;    /* Accelerator */
  44.     int         s_accept;    /* Nonzero for accepting state */
  45. } state;
  46.  
  47. /* A DFA */
  48.  
  49. typedef struct {
  50.     int         d_type;    /* Non-terminal this represents */
  51.     char        *d_name;    /* For printing */
  52.     int         d_initial;    /* Initial state */
  53.     int         d_nstates;
  54.     state        *d_state;    /* Array of states */
  55.     bitset         d_first;
  56. } dfa;
  57.  
  58. /* A grammar */
  59.  
  60. typedef struct {
  61.     int         g_ndfas;
  62.     dfa        *g_dfa;        /* Array of DFAs */
  63.     labellist     g_ll;
  64.     int         g_start;    /* Start symbol of the grammar */
  65.     int         g_accel;    /* Set if accelerators present */
  66. } grammar;
  67.  
  68. /* FUNCTIONS */
  69.  
  70. grammar *newgrammar Py_PROTO((int start));
  71. dfa *adddfa Py_PROTO((grammar *g, int type, char *name));
  72. int addstate Py_PROTO((dfa *d));
  73. void addarc Py_PROTO((dfa *d, int from, int to, int lbl));
  74. dfa *PyGrammar_FindDFA Py_PROTO((grammar *g, int type));
  75. char *typename Py_PROTO((grammar *g, int lbl));
  76.  
  77. int addlabel Py_PROTO((labellist *ll, int type, char *str));
  78. int findlabel Py_PROTO((labellist *ll, int type, char *str));
  79. char *PyGrammar_LabelRepr Py_PROTO((label *lb));
  80. void translatelabels Py_PROTO((grammar *g));
  81.  
  82. void addfirstsets Py_PROTO((grammar *g));
  83.  
  84. void PyGrammar_AddAccelerators Py_PROTO((grammar *g));
  85. void PyGrammar_RemoveAccelerators Py_PROTO((grammar *));
  86.  
  87. void printgrammar Py_PROTO((grammar *g, FILE *fp));
  88. void printnonterminals Py_PROTO((grammar *g, FILE *fp));
  89.  
  90. #ifdef __cplusplus
  91. }
  92. #endif
  93. #endif /* !Py_GRAMMAR_H */
  94.